package com.mapforge.gui.frames.tileset;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import com.mapforge.collection.WeakReferenceInstanceProvider;
import com.mapforge.listener.TileMapCreationEvent;
import com.mapforge.listener.TileMapCreationListener;
import com.mapforge.listener.TilesetEditListener;

public class TilesetEditorDialogProvider extends
		WeakReferenceInstanceProvider<TilesetEditorDialog> implements
		TileMapCreationListener, ActionListener {
	/**
	 * TilesetEditor must know about its parent for centering when visible
	 */
	private JFrame parent;
	List<TilesetEditListener> tilesetEditListeners;

	public TilesetEditorDialogProvider(JFrame parent) {
		this.parent = parent;
		tilesetEditListeners = new ArrayList<TilesetEditListener>();
	}

	protected TilesetEditorDialog createNewInstance() {
		TilesetEditorDialog dialog = new TilesetEditorDialog(parent,
				tilesetEditListeners);
		return dialog;
	}

	public void addTilesetEditListener(TilesetEditListener listener) {
		tilesetEditListeners.add(listener);
	}

	public boolean removeTilesetEditListener(TilesetEditListener listener) {
		return tilesetEditListeners.remove(listener);
	}

	public void clearTilesetEditListeners() {
		tilesetEditListeners.clear();
	}

	public void tileMapCreationPerformed(TileMapCreationEvent mapCreationEvent) {

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.getInstance().setVisible(true);
	}
}
